using PaperPlaneTools;
using System;
using UnityEngine;
using Voodoo.Sauce.Internal.Analytics;

namespace Voodoo.Sauce.Internal.AppRater
{
	internal class AppRater : MonoBehaviour
	{
		private static int _minimumGamesPlayed;

		private void Awake()
		{
			UnityEngine.Object.DontDestroyOnLoad(base.gameObject);
		}

		private void Start()
		{
			VoodooAnalytics.OnGamePlayed = (Action<int, bool>)Delegate.Combine(VoodooAnalytics.OnGamePlayed, new Action<int, bool>(OnGamePlayed));
		}

		private void OnGamePlayed(int gameCount, bool isHighscore)
		{
			if (_minimumGamesPlayed > 0 && gameCount >= _minimumGamesPlayed && (gameCount == _minimumGamesPlayed || isHighscore))
			{
				TryToShow();
			}
		}

		internal static void Initialize(string appstoreAppId, string playstoreAppId, int delayAfterLaunchInSeconds, int postponeCooldownInSeconds, int minimumGamesPlayed)
		{
			_minimumGamesPlayed = minimumGamesPlayed;
			RateBox.Instance.Init(RateBox.GetStoreUrl(appstoreAppId, playstoreAppId), new RateBoxConditions
			{
				MinSessionCount = 0,
				MinCustomEventsCount = 0,
				DelayAfterInstallInSeconds = delayAfterLaunchInSeconds,
				DelayAfterLaunchInSeconds = delayAfterLaunchInSeconds,
				PostponeCooldownInSeconds = postponeCooldownInSeconds,
				RequireInternetConnection = true
			}, new RateBoxTextSettings
			{
				Title = "Like the game?",
				RateButtonTitle = "Rate",
				RejectButtonTitle = string.Empty,
				PostponeButtonTitle = "Later",
				Message = "Please take a moment to rate us."
			}, new RateBoxSettings
			{
				UseIOSReview = true
			});
		}

		internal static void SetCustomAlert(IAlertPlatformAdapter customAlert)
		{
			RateBox.Instance.AlertAdapter = customAlert;
		}

		internal static void TryToShow()
		{
			RateBox.Instance.Show();
		}

		internal static void ForceShow()
		{
			RateBox.Instance.ForceShow();
		}
	}
}
